package gatperdut.chato.core.messaging.replies;

import gatperdut.chato.core.ChatoServer;
import gatperdut.chato.core.messaging.grammar.messinfo.ListRoomsInfo;
import gatperdut.chato.core.room.RoomController;

import org.json.simple.JSONArray;

public class ListRoomsReply extends Reply {

    public ListRoomsReply( ListRoomsInfo listInfo, ChatoServer chatoServer ) {
        super( listInfo, chatoServer );
    }

    @Override
    public String send() {
        RoomController[] allRoomsArray = getRoomsPackager().toArray( getChatoServer().getRoomHandler().getRoomToController().values().toArray() );
        JSONArray allRoomsJA = getRoomsPackager().packageAll( allRoomsArray );
        return allRoomsJA.toJSONString();
    }

    @Override
    public ListRoomsInfo getMessageInfo() {
        return (ListRoomsInfo) super.getMessageInfo();
    }

}
